home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / HMarqueeCaption 1.1 / HMarqueeCaption.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-07-15  |  10.6 KB  |  423 lines  |  [TEXT/CWIE]

  1. /*******************************************************************************\
  2. |                                                                                |
  3. |    HMarqueeCaption.h ©1997 John C. Daub. All rights reserved.                    |
  4. |    See the file "HMarqueeCaption README" for full details, instructions,        |
  5. |    changes, licensing agreement, etc.  Due to the important information        |
  6. |    included in that file, if you did not receive a copy of it, please contact    |
  7. |    the author for a copy.                                                        |
  8. |                                                                                |
  9. |    John C. Daub <mailto:hsoi@eden.com>                                            |
  10. |    <http://www.eden.com/~hsoi/>  <http://www.eden.com/~hsoi/prog.html>            |
  11. |                                                                                |
  12. \*******************************************************************************/
  13.  
  14.  
  15. #ifndef _H_HMarqueeCaption
  16. #define _H_HMarqueeCaption
  17. #pragma once
  18.  
  19.  
  20. #if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
  21.     #pragma import on
  22. #endif
  23.  
  24.  
  25. #include <PP_Prefix.h>
  26. #include <LPane.h>
  27. #include <LPeriodical.h>
  28. #include <LStream.h>
  29. #include <UMemoryMgr.h>
  30.  
  31. #ifndef __QUICKDRAW__
  32. #include <QuickDraw.h>
  33. #endif
  34.  
  35. #ifndef __QDOFFSCREEN__
  36. #include <QDOffscreen.h>
  37. #endif
  38.  
  39.  
  40. class    HMarqueeCaption :    public LPane,
  41.                             public LPeriodical
  42. {
  43.  
  44. public:
  45.  
  46.         enum { class_ID = 'MQcp' };
  47.  
  48.     #if ( __PowerPlant__ < 0x01608000 ) // version 1.6/CW11
  49.             static HMarqueeCaption*    CreateFromStream(LStream *inStream);
  50.     #endif
  51.  
  52.  
  53.                             HMarqueeCaption();
  54.                             HMarqueeCaption(const HMarqueeCaption &inOriginal);
  55.                             HMarqueeCaption(const SPaneInfo &inPaneInfo,
  56.                                             ResIDT    inTextID,
  57.                                             ResIDT    inTextTraitsID,
  58.                                             Int16    inDelay = 1,
  59.                                             Int16    inScrollAmount = 1,
  60.                                             Boolean    inResetOnResize = false );
  61.                             HMarqueeCaption(LStream *inStream);
  62.         virtual                ~HMarqueeCaption();
  63.         
  64.                 HMarqueeCaption&    operator=(const HMarqueeCaption &inOriginal);
  65.                 
  66.         virtual    void        SpendTime( const EventRecord &inMacEvent );
  67.         virtual void        Draw( RgnHandle inSuperDrawRgnH );
  68.  
  69.         virtual    ResIDT        GetTextTraitsID() const;
  70.         virtual void        SetTextTraitsID( const ResIDT inTextTraitsID);
  71.         
  72.         virtual    void        StripCRLF();
  73.         
  74.         virtual    void        SetTextHandle( Handle inTextH );
  75.         
  76.         virtual    ResIDT        GetTextID() const;
  77.         virtual    void        SetTextID( const ResIDT inTextID );
  78.         
  79.         virtual    Uint16        GetDelay() const;
  80.         virtual    void        SetDelay( const Uint16 inDelay );
  81.         
  82.         virtual    Int16        GetScrollAmount() const;
  83.         virtual    void        SetScrollAmount( const Int16 inScrollAmount );
  84.         
  85.         virtual    Boolean        GetResetOnResize() const;
  86.         virtual    void        SetResetOnResize( const Boolean inResetOnResize );
  87.         
  88.         virtual void        ResizeFrameBy(Int16 inWidthDelta, Int16 inHeightDelta,
  89.                                             Boolean inRefresh);
  90.  
  91.  
  92. protected:
  93.  
  94.         virtual void        DrawSelf();
  95.         virtual void        ActivateSelf();
  96.         virtual void        DeactivateSelf();
  97.  
  98.         virtual    void        Reset();
  99.  
  100.         virtual    void        AllocateGWorld();
  101.         virtual    void        DestroyGWorld();
  102.  
  103.         virtual    Int16        GetStringHeight() const;
  104.         virtual    void        SetStringHeight( const Int16 inHeight );
  105.         
  106.         virtual    Int32        GetLastEvent() const;
  107.         virtual    void        SetLastEvent( const Int32 inLastEvent );
  108.         
  109.         virtual    Uint32        GetTextLength() const;
  110.         virtual    void        SetTextLength();
  111.         virtual    void        SetTextLength( const Uint32 inLength );
  112.         
  113.         virtual    Int16        GetOffset() const;
  114.         virtual    void        SetOffset( const Int16 inOffset );
  115.         virtual    void        IncrementOffset( const Int16 inDelta );
  116.                 
  117. private:
  118.  
  119.                 void        InitMarqueeCaption();
  120.  
  121.                 Int16        mStrHeight;
  122.                 Int32        mLastEvent;
  123.                 GWorldPtr    mGWorld;
  124.                 Uint32        mTextLength;
  125.                 Int16        mOffset;
  126.  
  127.                 Handle        mTextH;
  128.  
  129.                 ResIDT        mTextID;
  130.                 ResIDT        mTextTraitsID;
  131.                 Uint16        mDelay;
  132.                 Int16        mScrollAmount;
  133.                 Boolean        mResetOnResize;
  134.  
  135. };
  136.  
  137.  
  138. //============================================================================
  139. //        ••• Inlines
  140. //============================================================================
  141.  
  142. //============================================================================
  143. //    • GetStringHeight                        [protected, virtual]
  144. //============================================================================
  145. //    Return the height of the string
  146.  
  147. inline
  148. Int16
  149. HMarqueeCaption::GetStringHeight() const
  150. {
  151.     return mStrHeight;
  152. }
  153.  
  154.  
  155. //============================================================================
  156. //    • SetStringHeight                        [protected, virtual]
  157. //============================================================================
  158. //    Set the string height to the given value
  159.  
  160. inline
  161. void
  162. HMarqueeCaption::SetStringHeight(
  163.     const Int16 inHeight )
  164. {
  165.     mStrHeight = inHeight;
  166. }
  167.  
  168.  
  169. //============================================================================
  170. //    • GetLastEvent                            [protected, virtual]
  171. //============================================================================
  172. //    Returns the time (in ticks) of the last event
  173.  
  174. inline
  175. Int32
  176. HMarqueeCaption::GetLastEvent() const
  177. {
  178.     return mLastEvent;
  179. }
  180.  
  181.  
  182. //============================================================================
  183. //    • SetLastEvent                            [protected, virtual]
  184. //============================================================================
  185. //    Set the time of the last event (in ticks)
  186.  
  187. inline
  188. void
  189. HMarqueeCaption::SetLastEvent(
  190.     const Int32 inLastEvent )
  191. {
  192.     mLastEvent = inLastEvent;
  193. }
  194.  
  195.  
  196. //============================================================================
  197. //    • GetTextLength                            [protected, virtual]
  198. //============================================================================
  199. //    Return the length of the text string
  200.  
  201. inline
  202. Uint32
  203. HMarqueeCaption::GetTextLength() const
  204. {
  205.     return mTextLength;
  206. }
  207.  
  208.  
  209. //============================================================================
  210. //    • SetTextLength                            [protected, virtual]
  211. //============================================================================
  212. //    Set the length of the text string to the given value
  213.  
  214. inline
  215. void
  216. HMarqueeCaption::SetTextLength(
  217.     const Uint32 inLength )
  218. {
  219.     mTextLength = inLength;
  220. }
  221.  
  222.  
  223. //============================================================================
  224. //    • SetTextLength                            [protected, virtual]
  225. //============================================================================
  226. //    Calculate the length of the text string and store the value
  227.  
  228. inline
  229. void
  230. HMarqueeCaption::SetTextLength()
  231. {
  232.     SignalIf_(mTextH == nil);
  233.     
  234.     StHandleLocker    lock(mTextH);
  235.     mTextLength = ::TextWidth( *mTextH, 0, ::GetHandleSize(mTextH) );
  236. }
  237.  
  238.  
  239. //============================================================================
  240. //    • GetOffset                                [protected, virtual]
  241. //============================================================================
  242. //    Return the offset
  243.  
  244. inline
  245. Int16
  246. HMarqueeCaption::GetOffset() const
  247. {
  248.     return mOffset;
  249. }
  250.  
  251.  
  252. //============================================================================
  253. //    • SetOffset                                [protected, virtual]
  254. //============================================================================
  255. //    Set the offset to the given amount
  256.  
  257. inline
  258. void
  259. HMarqueeCaption::SetOffset(
  260.     const Int16 inOffset )
  261. {
  262.     mOffset = inOffset;
  263. }
  264.  
  265.  
  266. //============================================================================
  267. //    • IncrementOffset                        [protected, virtual]
  268. //============================================================================
  269. //    Increase the offset by the given amount (negative values will of course
  270. //    decrease)
  271.  
  272. inline
  273. void
  274. HMarqueeCaption::IncrementOffset(
  275.     const Int16 inDelta )
  276. {
  277.     mOffset += inDelta;
  278. }
  279.  
  280.  
  281. //============================================================================
  282. //    • GetTextID                                [public, virtual]
  283. //============================================================================
  284. //    Return the ResIDT of the 'TEXT' resource
  285.  
  286. inline
  287. ResIDT
  288. HMarqueeCaption::GetTextID() const
  289. {
  290.     return mTextID;
  291. }
  292.  
  293.  
  294. //============================================================================
  295. //    • SetTextID                                [public, virtual]
  296. //============================================================================
  297. //    Set the ResIDT of the 'TEXT' resource
  298.  
  299. inline
  300. void
  301. HMarqueeCaption::SetTextID(
  302.     const ResIDT inTextID )
  303. {
  304.     mTextID = inTextID;
  305. }
  306.  
  307.  
  308. //============================================================================
  309. //    • GetTextTraitsID                        [public, virtual]
  310. //============================================================================
  311. //    Return the ResIDT of the 'Txtr' resource
  312.  
  313. inline
  314. ResIDT
  315. HMarqueeCaption::GetTextTraitsID() const
  316. {
  317.     return mTextTraitsID;
  318. }
  319.  
  320. //============================================================================
  321. //    • SetTextTraitsID                        [public, virtual]
  322. //============================================================================
  323. //    Set the ResIDT to the given 'Txtr', and reset (since this could cause
  324. //    enough graphical changes)
  325.  
  326. inline
  327. void
  328. HMarqueeCaption::SetTextTraitsID(
  329.     const ResIDT inTextTraitsID )
  330. {
  331.     mTextTraitsID = inTextTraitsID;
  332.     Reset();
  333. }
  334.  
  335.  
  336. //============================================================================
  337. //    • GetDelay                                [public, virtual]
  338. //============================================================================
  339. //    Return the delay amount (in ticks)
  340.  
  341. inline
  342. Uint16
  343. HMarqueeCaption::GetDelay() const
  344. {
  345.     return mDelay;
  346. }
  347.  
  348.  
  349. //============================================================================
  350. //    • SetDelay                                [public, virtual]
  351. //============================================================================
  352. //    Set the delay amount (in ticks) to the given amount
  353.  
  354. inline
  355. void
  356. HMarqueeCaption::SetDelay(
  357.     const Uint16 inDelay )
  358. {
  359.     mDelay = inDelay;
  360. }
  361.  
  362.  
  363. //============================================================================
  364. //    • GetScrollAmount                        [public, virtual]
  365. //============================================================================
  366. //    Returns the scroll amount (in pixels)
  367.  
  368. inline
  369. Int16
  370. HMarqueeCaption::GetScrollAmount() const
  371. {
  372.     return mScrollAmount;
  373. }
  374.  
  375.  
  376. //============================================================================
  377. //    • SetScrollAmount                        [public, virtual]
  378. //============================================================================
  379. //    Set the scroll amount to the given number of pixels
  380.  
  381. inline
  382. void
  383. HMarqueeCaption::SetScrollAmount(
  384.     const Int16 inScrollAmount )
  385. {
  386.     mScrollAmount = inScrollAmount;
  387. }
  388.  
  389.  
  390. //============================================================================
  391. //    • GetResetOnResize                        [public, virtual]
  392. //============================================================================
  393. //     Return true if we reset the caption upon resizing
  394.  
  395. inline
  396. Boolean
  397. HMarqueeCaption::GetResetOnResize() const
  398. {
  399.     return mResetOnResize;
  400. }
  401.  
  402.  
  403. //============================================================================
  404. //    * SetResetOnResize                        [public, virtual]
  405. //============================================================================
  406. //    Set to true if you wish to  have the caption reset itself upon resizing
  407.  
  408. inline
  409. void
  410. HMarqueeCaption::SetResetOnResize(
  411.     const Boolean inResetOnResize )
  412. {
  413.     mResetOnResize = inResetOnResize;
  414. }
  415.  
  416.  
  417.  
  418. #if defined(__CFM68K__) && !defined(__USING_STATIC_LIBS__)
  419.     #pragma import reset
  420. #endif
  421.  
  422.  
  423. #endif /* #define _H_HMarqueeCaption */